package net.fuzui.StudentInfo.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class NoCacheFilter implements Filter {

    @Override
    public void destroy(){
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
        HttpServletResponse response = (HttpServletResponse)resp;

        response.setDateHeader("Expires", -1);				//告诉浏览器数据能够缓存多长时间，-1或0表示不缓存
        response.setHeader("Cache_Control", "no-cache");	//支持HTTP 1.1，告诉浏览器要不要缓存数据，如“no-cache”
        response.setHeader("Pragma", "no-cache");			//支持HTTP 1.0。告诉浏览器要不要缓存数据，如“no-cache”

        chain.doFilter(req, resp);
    }

    @Override
    public void init(FilterConfig arg0) throws ServletException	{
    }
}
